<template>
	<view>
		<text></text>
		<view style="margin: 30rpx;">
			<uni-section title="身份证正面" type="line">
				<view>
					<image mode="aspectFit" :src="zsrc" @click="tj()"></image>
				</view>
			</uni-section>
			<uni-section title="身份证反面" type="line">
				<view>
					<image mode="aspectFit" :src="bsrc" @click="btj()"></image>
				</view>
			</uni-section>
			<text>姓名\n</text>
			<input type="text" :value="zperson.name"  class="bo"/>
			<text>身份证号\n</text>
			<input type="text" :value="zperson.idNumber" class="bo"/>
			<text>性别\n</text>
			<input type="text" :value="zperson.sex" class="bo"/>
			<text>有效期止\n</text>
			<input type="text" :value="bperson.validity" class="bo"/>
			<text>有效期止\n</text>
			<input type="text" :value="bperson.invalid" class="bo"/>
		</view>
		<view>
			
		</view>
		<view style="display: flex; flex-direction: row; margin: 15rpx;">
			<view class="flex.item"><button size="mini" @click="back()">取消</button></view>
			<view class="flex.item"></view>
			<view class="flex.item"><button size="mini" @click="examine()">确认</button></view>
		</view>
		{{zperson.zid}}
	</view>
</template>

<script>

	export default {
		data() {
			return {
				zsrc:"../../static/iconfont/添加.png",
				bsrc:"../../static/iconfont/添加.png",
				zperson:{
									
									
									idNumber: '',
									name: '',
									
									validity:'',
									invalid:'',
									zid:''
									
								},
				bperson:{
									validity:'',
									invalid:''
								},
								aa:{},
								zid:''
			}
		},
		created() {
			this.zid=this.$store.state.id;
			
			console.log(this.$store.state.id)
			const baseUrl="http://localhost:8888"
			uni.request({
				url:baseUrl+'/s/legalperson/addZid/'+this.zid,
				method:"GET"
			}).then(res=>{
				console.log(res)
				})
		},
		methods: {
			back(){
				uni.navigateBack()
			},
			examine(){
				const baseUrl="http://localhost:8888"
											uni.request({
												url:baseUrl+'/s/legalperson/add',
												method:"POST",
												data:this.zperson
											}).then(res=>{
												uni.redirectTo({
													url:'/pages/auth/auth'
												})
												
											})
			},
			tj(){
				
				var this_=this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						console.log(JSON.stringify(res.tempFilePaths));
						this_.zsrc=res.tempFilePaths
						this_.file=this_.zsrc
						const baseUrl="http://localhost:8888";
						uni.uploadFile({
							
							url: baseUrl+'/s/s/ocr',
							name: 'file',
							filePath:this_.file[0],
							header: {
								'Content-type':'multipart/form-data'
							},
							success: (uploadFileRes) => {
								console.log(this_.$store.state.id)
								// console.info(uploadFileRes.data)
								// console.info(uploadFileRes.data.split(","))
								// console.log(uploadFileRes, '上传成功')
								// console.log("map"+uploadFileRes.data.tp)
								var p = JSON.parse(uploadFileRes.data)
								// console.log(p.data)
								// console.log(p.data.sj)
								// var a=p.data.sj+" "
								// console.log(a)
								// //图片路径
								// console.log(p.data.tp)
								// this_.aa = p.data.sj
								// console.log( typeof p1)
								// var p2 = JSON.parse(a)
								// console.log(p2)
								// console.log(p2.data)
								// console.log(p.data.sj)
								// console.log(p.data.sj.data)
								this_.zperson=p.data.face.data
								
								this_.zperson.zid=this_.zid
								// const baseUrl="http://localhost:8888"
								// uni.request({
								// 	url:baseUrl+'/s/ignin/yzm',
								// 	method:"Get",
								// 	data:this.form
								// }).then(res=>{
								// 	this.yzm=res.data
								// 	this.$refs.uToast.show({
								// 		type: 'success',
								// 		title: res.data
								// 		})
								// })
								
								
								
								
								
								//获取阿里云路径
								uni.uploadFile({
									
									url: baseUrl+'/s/ignin/ac/'+this_.zid,
									name: 'file',
									filePath:this_.file[0],
									header: {
										'Content-type':'multipart/form-data'
									},
									success: (uploadFileRes) => {
										// console.log(uploadFileRes)
										var a=JSON.parse(uploadFileRes.data)
										console.log(a)
									},
									})
									
								
								
								
								
								
							},
							fail: (res) => {
								console.log(res, '上传失败')
							}
					})
					}
					})
			},
			btj(){
				console.log(this.$store.state.id)
				var this_=this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						console.log(JSON.stringify(res.tempFilePaths));
						this_.bsrc=res.tempFilePaths
						console.info("-----")
						console.info(this_.file)
						this_.file=this_.bsrc
						const baseUrl="http://localhost:8888";
						uni.uploadFile({
							
							url: baseUrl+'/s/s/ocr',
							name: 'file',
							filePath:this_.file[0],
							header: {
								'Content-type':'multipart/form-data'
							},
							success: (uploadFileRes) => {
								var p= JSON.parse(uploadFileRes.data)
																var l =  p.data.back.data.validPeriod.split("-")
																this_.bperson.validity = l[0]
																this_.bperson.invalid = l[1]
																console.info(p.data.back.data.validPeriod.split("-"))
																console.log(uploadFileRes, '上传成功')
								
								
								
								uni.uploadFile({
									
									url: baseUrl+'/s/ignin/ac1/'+this_.zid,
									name: 'file',
									filePath:this_.file[0],
									header: {
										'Content-type':'multipart/form-data'
									},
									success: (uploadFileRes) => {
										// console.log(uploadFileRes)
										var a=JSON.parse(uploadFileRes.data)
										console.log(a.data)
									},
									})
							},
							fail: (res) => {
								console.info(this_.file)
								console.log(res, '上传失败')
							}
					})
					}
					})
			},
			
			
		}
	}
</script>

<style>
	.flex.item{
		width: 33.33%;
	}
	.bo{
		border: 1rpx solid black;
		width: 300rpx;
	}
</style>
